package com.lagou.subjectthree;

import java.io.File;
import java.io.IOException;
import java.nio.file.Files;

/**
 * 复制文件线程
 */
public class CopyFileThread extends Thread {
    //存文件夹路径
    private File file;
    private File fileCopy;

    public CopyFileThread(File file, File fileCopy) {
        this.file = file;
        this.fileCopy = fileCopy;
    }

    @Override
    public void run() {
        System.out.println("复制文件:" + file.getName());
        //文件不存在就复制
        if (!fileCopy.exists()) {
            try {
                Files.copy(file.toPath(), fileCopy.toPath());
            } catch (IOException e) {
                e.printStackTrace();
            }
            System.out.println("复制文件:" + file.getName() + "完成");
        } else
            System.out.println("已存在无需复制！");
    }
}

